﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows.Input;
using MathematicallySafe.HeadCounter.Commands;

namespace MathematicallySafe.HeadCounter.Dialogs
{
    public abstract class DialogControllerBase : INotifyPropertyChanged
    {
        private DelegateCommand _okCommand;
        private DelegateCommand _cancelCommand;

        public ICommand OkCommand
        {
            get
            {
                if (_okCommand == null)
                {
                    _okCommand = new DelegateCommand(Ok, CanClickOk);
                }

                return _okCommand;
            }
        }

        protected virtual bool CanClickOk()
        {
            return true;
        }

        protected abstract void Ok();

        public ICommand CancelCommand
        {
            get
            {
                if (_cancelCommand == null)
                {
                    _cancelCommand = new DelegateCommand(Cancel, CanClickCancel);
                }

                return _cancelCommand;
            }
        }

        protected virtual bool CanClickCancel()
        {
            return true;
        }

        protected virtual void Cancel() {}

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
